#pragma once
#include "afxwin.h"
#pragma warning(disable: 4482)
#include "LibWinUtilsDef.h"


#define COMB_SPLIT			"--"
#define EDITCTL_NAME		"Edit"
#define COMBCTL_NAME		"ComboBox"
#define BUTTONCTL_NAME		"Button"
#define DATECTL_NAME		"SysDateTimePick32"
#define LISTCTL_NAME		"SysListView32"
class WndHelper
{
	enum ControlType
	{
		Static,
		Edit,
		RichEdit,
		Combo,
	};

public:

	static CString GetCtlClassName( HWND hWnd )	
	{		
		ASSERT(hWnd != NULL);

		CString szClassName;		
		::GetClassName(hWnd, szClassName.GetBuffer(32), 32);
		szClassName.ReleaseBuffer();
		return szClassName;
	}
	static BOOL IsCombCtl( HWND pWnd )		
	{
		CString name = GetCtlClassName(pWnd);
		CString parentname = GetCtlClassName(::GetParent(pWnd));

		return  name== COMBCTL_NAME || parentname == COMBCTL_NAME;
	}

	BOOL SetCtlVal( UINT ctlID,const TCHAR* pVal );
	BOOL SetCtlVal( UINT ctlID,int Val );
	BOOL SetCtlVal( UINT ctlID,double Val );
};


//#define  WM_USER_CLOSEWINDOW   (WM_USER+ 1234)
class LIBWINUTILS_API CBaseForm : public CDialog
{
public:
	//DECLARE_DYNAMIC(CBaseForm)

	enum ShowInPos
	{
		Center = 0,
		FixPos = 1,
	};
	virtual CString GetTitle() const = 0;


	CBaseForm(UINT nIDTemplate,CWnd* pParent = NULL);
	virtual ~CBaseForm(void);
	int GetResult() const
	{
		return m_result;
	}

	//if Form View The
	virtual BOOL AllowClose();



	BOOL ShowInView(CFormView* pParent,CBaseForm::ShowInPos pos = CBaseForm::ShowInPos::Center);



	static CSize GetDlgRectFromResource(int ResourceDlgID,HMODULE hmodule = GetModuleHandle(NULL));
	CSize GetResSize() const;
protected:
	CFormView* pParent;
	int m_result;

private:
	CSize m_resSize;

	virtual BOOL PreTranslateMessage( MSG* pMsg );

private:
	CBaseForm(const CBaseForm& objectSrc);
	void operator=(const CBaseForm& objectSrc);
protected:
	virtual void OnOK();

	virtual void OnCancel();

};




class AutoResSwitch
{
public:
	AutoResSwitch(const TCHAR* dll)
	{
		hDLL=GetModuleHandle(dll);

		hEXE=AfxGetResourceHandle();

		AfxSetResourceHandle((HINSTANCE)hDLL); 

	}
	~AutoResSwitch()
	{
		AfxSetResourceHandle(hEXE); 
	}
private:
	HINSTANCE hEXE;
	HMODULE hDLL;
};
#define SWITCHRES(xx) AutoResSwitch  __swithres__(xx)